package com.zl.credit.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zl.credit.entity.CreditConnection;
import com.zl.credit.entity.CreditProgress;
import com.zl.credit.service.CreditProgressService;
import com.zl.credit.service.impl.CreditConnectionServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author anonymous
 * @since 2020-07-14
 */
@Controller
@RequestMapping("/credit-connection")
public class CreditConnectionController {

    @Autowired
    private CreditConnectionServiceImpl connectionService;

    @Autowired
    private CreditProgressService progressService;

    /**
     * 向联系人表插入一条记录
     * @param connection
     * @return
     */
    @RequestMapping(value = "/addconnection",method = RequestMethod.POST)
    public String addconnection(CreditConnection connection,String name){
        //生成主键
        String substring = UUID.randomUUID().toString().substring(0, 6);
        connection.setConId(substring);
        connectionService.addconnection(connection);
        //1.查询当前用户的申请进度表
        CreditProgress progress = progressService.selectprogressstatus(name);
        //更改基本表id和
        progress.setConId(substring);
        progress.setAuditStatus("审核中");
        progress.setAuditProgress("申请中");
        progress.setApplyTime(new Date());
        //2.更新到申请进度表
        progressService.updateprogress(progress);
        return "success";
    }

    /**
     * 根据主键id查询联系人表
     * @param conId
     * @return
     */
    @RequestMapping(value = "QueryByid",method = RequestMethod.GET)
    public String QueryByid(String conId){
        System.out.println("conId = " + conId);
        CreditConnection connection = connectionService.getById(conId);
        System.out.println(connection);
        return "index";
    }
}
